// pages/order/order.js
const interfaces = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
    totalPrice: 0,
    address: {},
    addressId: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (wx.getStorageSync('addressId')){
      this.setData({
        addressId: wx.getStorageSync("addressId")
      })
    }
    this.getDetail()
  },
  /**
   * 获取订单信息
   */
  getDetail(){
    let openId = wx.getStorageSync('openId')
    let self = this
    let price = 0
    wx.request({
      url: interfaces.orderDetail,
      data:{
        openId: openId,
        addressId: self.data.addressId
      },
      success(res){
        console.log(res)
        let goodsList = res.data.goodsList;
        goodsList.forEach((item)=>{
          price += item.number * item.retail_price
        })
        self.setData({
          listData: res.data.goodsList,
          totalPrice: price,
          address: res.data.address
        })
      }
    })
  },
  toSelect(){
    wx.navigateTo({
      url: '/pages/selectAddress/selectAddress'
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})